#include "BaseType.h"
#include "Tracer.h"
#include "FSMachine.h"
#include "Thread.h"
using namespace libemb;

class StateIdle:public FSHandler{
DECL_CLASSNAME(StateIdle)
public:
	void handleState()
	{
		if (m_circles--<0)
		{
			return;
		}
		TRACE_DBG_CLASS("enter IDLE state...\n");
		Thread::msleep(2000);
		setState(1);
	}
private:
	int m_circles{2};
};

class StateStart:public FSHandler{
DECL_CLASSNAME(StateStart)
public:
	void handleState()
	{
		TRACE_DBG_CLASS("enter START state...\n");
		Thread::msleep(2000);
		setState(2);
	}
};

class StateStop:public FSHandler{
DECL_CLASSNAME(StateStop)
public:
	void handleState()
	{
		TRACE_DBG_CLASS("enter STOP state...\n");
		Thread::msleep(2000);
		setState(0);
	}
};

void testFSMachine(void)
{
    TRACE_INFO("FSMachine test start >>>>>>\n");
	FSMachine machine;
	StateIdle idle;
	StateStart start;
	StateStop stop;
	machine.registerState(0,idle);
	machine.registerState(1,start);
	machine.registerState(2,stop);
	machine.setState(0);
    TRACE_INFO("FSMachine test finished <<<<<<\n");
}
